﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ebooom.Leads.Business.AuthorRole
{
    public class AuthorRoleUtils
    {
        /// <summary>
        /// 权限验证
        /// </summary>
        /// <param name="roleCode">权限代码</param>
        /// <param name="verifyRoleCode">要验证的权限数值</param>
        /// <returns>是否拥有权限</returns>
        public static bool IsHasRight(long? roleCode, long verifyRoleCode)
        {
            if (roleCode != null)
            {
                if ((roleCode & verifyRoleCode) != 0)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 附加权限
        /// </summary>
        /// <param name="currentCode">当前权限数值</param>
        /// <param name="roleCode">要附加的权限代码</param>
        /// <returns>附加后的权限数值</returns>
        public static long SetRoleForUser(long currentCode, long roleCode)
        {
            return (currentCode | roleCode);
        }

        /// <summary>
        /// 移除权限
        /// </summary>
        /// <param name="currentCode">当前权限数值</param>
        /// <param name="roleCode">要移除的权限代码</param>
        /// <returns>移除后的权限数值</returns>
        public static long RemoveRoleFromUser(long currentCode, long roleCode)
        {
            return (currentCode & (~roleCode));
        }

    }
}
